package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {

    @Select("select count(id) from dish where category_id=#{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 插入菜品表，一个菜品
     */

//    @AutoFill(value = OperationType.INSERT)
//    @Insert("insert into dish(name,category_id,price,image,description,status,create_time,update_time,create_user,update_user) values "+
//    "(#{name},#{categoryId},#{price},#{image},#{description},#{status})"
//    )
//    void insert(Dish dish);

    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);

    /**
     * 菜品分页查询
     * @param dishPageQueryDTO
     * @return
     * 肯定使用动态sql
     */
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 根据id查询菜品
     * @param id
     * @return
     */
    @Select("select * from dish where id=#{id}")
    Dish getById(Long id);

    /**
     * 根据id删除菜品数据
     * @param id
     */
    @Delete("delete from dish where id=#{id}")
    void deleteById(Long id);

    /**
     * 批量删除菜品数据
     * @param ids
     */
    void deleteByIds(List<Long> ids);

    /**
     * 修改菜品数据
     * @param dish
     */
//    @AutoFill(value = OperationType.UPDATE)
//    @Update("update dish set name=#{name}, price=#{price}, descripition=#{description},status=#{status},update_time=#{updateTime},update_user=#{updateUser}")
//    void update(Dish dish);

    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);
}
